import wx

class EffectsConfiguration(wx.Panel):

    def __init__(self, parent, model):
        wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
        self.parent = parent
        self.model = model

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        #FX Configuration
        fxeffects = wx.StaticBox(self, wx.ID_ANY, "FX Configuration")
        sizerCombo = wx.BoxSizer(wx.HORIZONTAL)
        fx1Label = wx.StaticText(self, label="FX 1")
        fx2Label = wx.StaticText(self, label="FX 2")
        sizerFX1 = wx.BoxSizer(wx.VERTICAL)
        sizerFX2 = wx.BoxSizer(wx.VERTICAL)
        self.fx1 = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=self.model.getEffectsList(),  style=wx.CB_READONLY)
        self.fx2 = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=self.model.getEffectsList(),  style=wx.CB_READONLY)

        sizerFX1.Add(fx1Label, 0, wx.ALL, 5)
        sizerFX1.Add(self.fx1, 0, wx.ALL, 5)
        sizerFX2.Add(fx2Label, 0, wx.ALL, 5)
        sizerFX2.Add(self.fx2, 0, wx.ALL, 5)

        sizerCombo.Add(sizerFX1)
        sizerCombo.Add(sizerFX2)

        fxBox = wx.StaticBoxSizer(fxeffects, wx.VERTICAL)
        fxBox.SetMinSize((300, 150))
        fxBox.Add(sizerCombo)


        #Grid Configuration
        fraction = ["1", "0.5", "0.25", "0.125", "0.0605", "0.03025"]
        hl = ["hatch", "latch"]

        grid = wx.StaticBox(self, wx.ID_ANY, "Grid Configuration")

        self.btn1loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn2loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn3loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn4loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn5loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn6loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn7loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn8loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn9loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn10loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn11loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn12loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn13loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn14loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn15loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        self.btn16loop = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=fraction,  style=wx.CB_READONLY)
        

        self.btn1hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn2hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn3hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn4hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn5hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn6hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn7hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn8hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn9hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn10hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn11hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn12hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn13hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn14hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn15hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)
        self.btn16hl = wx.ComboBox(self, 1, pos=(50, 170), size=(150, -1), choices=hl,  style=wx.CB_READONLY)

        btn1Label = wx.StaticText(self, label="1")
        btn2Label = wx.StaticText(self, label="2")
        btn3Label = wx.StaticText(self, label="3")
        btn4Label = wx.StaticText(self, label="4")
        btn5Label = wx.StaticText(self, label="5")
        btn6Label = wx.StaticText(self, label="6")
        btn7Label = wx.StaticText(self, label="7")
        btn8Label = wx.StaticText(self, label="8")
        btn9Label = wx.StaticText(self, label="9")
        btn10Label = wx.StaticText(self, label="10")
        btn11Label = wx.StaticText(self, label="11")
        btn12Label = wx.StaticText(self, label="12")
        btn13Label = wx.StaticText(self, label="13")
        btn14Label = wx.StaticText(self, label="14")
        btn15Label = wx.StaticText(self, label="15")
        btn16Label = wx.StaticText(self, label="16")

        self.btn1Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn2Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn3Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn4Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn5Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn6Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn7Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn8Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn9Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn10Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn11Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn12Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn13Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn14Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn15Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)
        self.btn16Sample = wx.ComboBox(self, wx.ID_ANY, pos=(50, 170), size=(150, -1), choices=[],  style=wx.CB_READONLY)

        sizerBtn1 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn1.Add(btn1Label, 0, wx.ALL, 5)
        sizerBtn1.Add(self.btn1Sample, 0, wx.ALL, 5)
        sizerBtn1.Add(self.btn1loop, 0, wx.ALL, 5)
        sizerBtn1.Add(self.btn1hl, 0, wx.ALL, 5)

        sizerBtn2 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn2.Add(btn2Label, 0, wx.ALL, 5)
        sizerBtn2.Add(self.btn2Sample, 0, wx.ALL, 5)
        sizerBtn2.Add(self.btn2loop, 0, wx.ALL, 5)
        sizerBtn2.Add(self.btn2hl, 0, wx.ALL, 5)

        sizerBtn3 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn3.Add(btn3Label, 0, wx.ALL, 5)
        sizerBtn3.Add(self.btn3Sample, 0, wx.ALL, 5)
        sizerBtn3.Add(self.btn3loop, 0, wx.ALL, 5)
        sizerBtn3.Add(self.btn3hl, 0, wx.ALL, 5)

        sizerBtn4 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn4.Add(btn4Label, 0, wx.ALL, 5)
        sizerBtn4.Add(self.btn4Sample, 0, wx.ALL, 5)
        sizerBtn4.Add(self.btn4loop, 0, wx.ALL, 5)
        sizerBtn4.Add(self.btn4hl, 0, wx.ALL, 5)

        sizerRow1 = wx.BoxSizer(wx.HORIZONTAL)
        sizerRow1.Add(sizerBtn1, 0, wx.ALL, 5)
        sizerRow1.Add(sizerBtn2, 0, wx.ALL, 5)
        sizerRow1.Add(sizerBtn3, 0, wx.ALL, 5)
        sizerRow1.Add(sizerBtn4, 0, wx.ALL, 5)

        sizerBtn5 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn5.Add(btn5Label, 0, wx.ALL, 5)
        sizerBtn5.Add(self.btn5Sample, 0, wx.ALL, 5)
        sizerBtn5.Add(self.btn5loop, 0, wx.ALL, 5)
        sizerBtn5.Add(self.btn5hl, 0, wx.ALL, 5)

        sizerBtn6 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn6.Add(btn6Label, 0, wx.ALL, 5)
        sizerBtn6.Add(self.btn6Sample, 0, wx.ALL, 5)
        sizerBtn6.Add(self.btn6loop, 0, wx.ALL, 5)
        sizerBtn6.Add(self.btn6hl, 0, wx.ALL, 5)

        sizerBtn7 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn7.Add(btn7Label, 0, wx.ALL, 5)
        sizerBtn7.Add(self.btn7Sample, 0, wx.ALL, 5)
        sizerBtn7.Add(self.btn7loop, 0, wx.ALL, 5)
        sizerBtn7.Add(self.btn7hl, 0, wx.ALL, 5)

        sizerBtn8 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn8.Add(btn8Label, 0, wx.ALL, 5)
        sizerBtn8.Add(self.btn8Sample, 0, wx.ALL, 5)
        sizerBtn8.Add(self.btn8loop, 0, wx.ALL, 5)
        sizerBtn8.Add(self.btn8hl, 0, wx.ALL, 5)

        sizerRow2 = wx.BoxSizer(wx.HORIZONTAL)
        sizerRow2.Add(sizerBtn5, 0, wx.ALL, 5)
        sizerRow2.Add(sizerBtn6, 0, wx.ALL, 5)
        sizerRow2.Add(sizerBtn7, 0, wx.ALL, 5)
        sizerRow2.Add(sizerBtn8, 0, wx.ALL, 5)

        sizerBtn9 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn9.Add(btn9Label, 0, wx.ALL, 5)
        sizerBtn9.Add(self.btn9Sample, 0, wx.ALL, 5)
        sizerBtn9.Add(self.btn9loop, 0, wx.ALL, 5)
        sizerBtn9.Add(self.btn9hl, 0, wx.ALL, 5)

        sizerBtn10 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn10.Add(btn10Label, 0, wx.ALL, 5)
        sizerBtn10.Add(self.btn10Sample, 0, wx.ALL, 5)
        sizerBtn10.Add(self.btn10loop, 0, wx.ALL, 5)
        sizerBtn10.Add(self.btn10hl, 0, wx.ALL, 5)

        sizerBtn11 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn11.Add(btn11Label, 0, wx.ALL, 5)
        sizerBtn11.Add(self.btn11Sample, 0, wx.ALL, 5)
        sizerBtn11.Add(self.btn11loop, 0, wx.ALL, 5)
        sizerBtn11.Add(self.btn11hl, 0, wx.ALL, 5)

        sizerBtn12 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn12.Add(btn12Label, 0, wx.ALL, 5)
        sizerBtn12.Add(self.btn12Sample, 0, wx.ALL, 5)
        sizerBtn12.Add(self.btn12loop, 0, wx.ALL, 5)
        sizerBtn12.Add(self.btn12hl, 0, wx.ALL, 5)

        sizerRow3 = wx.BoxSizer(wx.HORIZONTAL)
        sizerRow3.Add(sizerBtn9, 0, wx.ALL, 5)
        sizerRow3.Add(sizerBtn10, 0, wx.ALL, 5)
        sizerRow3.Add(sizerBtn11, 0, wx.ALL, 5)
        sizerRow3.Add(sizerBtn12, 0, wx.ALL, 5)

        sizerBtn13 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn13.Add(btn13Label, 0, wx.ALL, 5)
        sizerBtn13.Add(self.btn13Sample, 0, wx.ALL, 5)
        sizerBtn13.Add(self.btn13loop, 0, wx.ALL, 5)
        sizerBtn13.Add(self.btn13hl, 0, wx.ALL, 5)

        sizerBtn14 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn14.Add(btn14Label, 0, wx.ALL, 5)
        sizerBtn14.Add(self.btn14Sample, 0, wx.ALL, 5)
        sizerBtn14.Add(self.btn14loop, 0, wx.ALL, 5)
        sizerBtn14.Add(self.btn14hl, 0, wx.ALL, 5)

        sizerBtn15 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn15.Add(btn15Label, 0, wx.ALL, 5)
        sizerBtn15.Add(self.btn15Sample, 0, wx.ALL, 5)
        sizerBtn15.Add(self.btn15loop, 0, wx.ALL, 5)
        sizerBtn15.Add(self.btn15hl, 0, wx.ALL, 5)

        sizerBtn16 = wx.BoxSizer(wx.VERTICAL)
        sizerBtn16.Add(btn16Label, 0, wx.ALL, 5)
        sizerBtn16.Add(self.btn16Sample, 0, wx.ALL, 5)
        sizerBtn16.Add(self.btn16loop, 0, wx.ALL, 5)
        sizerBtn16.Add(self.btn16hl, 0, wx.ALL, 5)

        sizerRow4 = wx.BoxSizer(wx.HORIZONTAL)
        sizerRow4.Add(sizerBtn13, 0, wx.ALL, 5)
        sizerRow4.Add(sizerBtn14, 0, wx.ALL, 5)
        sizerRow4.Add(sizerBtn15, 0, wx.ALL, 5)
        sizerRow4.Add(sizerBtn16, 0, wx.ALL, 5)

        save = wx.Button(self, wx.ID_ANY, "Save")
        save.Bind(wx.EVT_BUTTON, self.OnSave)

        sizerSave = wx.BoxSizer(wx.HORIZONTAL)
        sizerSave.Add(save, 0, wx.ALL, 5)
        
        gridBox = wx.StaticBoxSizer(grid, wx.VERTICAL)
        gridBox.SetMinSize((300, 150))
        gridBox.Add(sizerRow1)
        gridBox.Add(sizerRow2)
        gridBox.Add(sizerRow3)
        gridBox.Add(sizerRow4)
        gridBox.Add(sizerSave, 0, wx.ALL, 5)

        sizer.Add(gridBox, 0, wx.ALL, 5)
        sizer.Add(fxBox, 0, wx.ALL, 5)

        self.SetSizer(sizer)

    def updateParameter(self, select, value):
        select.Clear()
        parameters = self.model.getParameters(value)
        for param in parameters:
            select.Append(param)

    def updateCombo(self, combo):
        combo.Clear()
        filenames = self.model.getFilenames()
        for filename in filenames:
            combo.Append(filename.keys()[0])


    def OnSave(self, event):
        self.model.setGridOption("1", self.btn1loop.GetValue(), self.btn1hl.GetValue(), self.btn1Sample.GetValue())
        self.model.setGridOption("2", self.btn2loop.GetValue(), self.btn2hl.GetValue(), self.btn2Sample.GetValue())
        self.model.setGridOption("3", self.btn3loop.GetValue(), self.btn3hl.GetValue(), self.btn3Sample.GetValue())
        self.model.setGridOption("4", self.btn4loop.GetValue(), self.btn4hl.GetValue(), self.btn4Sample.GetValue())
        self.model.setGridOption("5", self.btn5loop.GetValue(), self.btn5hl.GetValue(), self.btn5Sample.GetValue())
        self.model.setGridOption("6", self.btn6loop.GetValue(), self.btn6hl.GetValue(), self.btn6Sample.GetValue())
        self.model.setGridOption("7", self.btn7loop.GetValue(), self.btn7hl.GetValue(), self.btn7Sample.GetValue())
        self.model.setGridOption("8", self.btn8loop.GetValue(), self.btn8hl.GetValue(), self.btn8Sample.GetValue())
        self.model.setGridOption("9", self.btn9loop.GetValue(), self.btn9hl.GetValue(), self.btn9Sample.GetValue())
        self.model.setGridOption("10", self.btn10loop.GetValue(), self.btn10hl.GetValue(), self.btn10Sample.GetValue())
        self.model.setGridOption("11", self.btn11loop.GetValue(), self.btn11hl.GetValue(), self.btn11Sample.GetValue())
        self.model.setGridOption("12", self.btn12loop.GetValue(), self.btn12hl.GetValue(), self.btn12Sample.GetValue())
        self.model.setGridOption("13", self.btn13loop.GetValue(), self.btn13hl.GetValue(), self.btn13Sample.GetValue())
        self.model.setGridOption("14", self.btn14loop.GetValue(), self.btn14hl.GetValue(), self.btn14Sample.GetValue())
        self.model.setGridOption("15", self.btn15loop.GetValue(), self.btn15hl.GetValue(), self.btn15Sample.GetValue())
        self.model.setGridOption("16", self.btn16loop.GetValue(), self.btn16hl.GetValue(), self.btn16Sample.GetValue())
        fx = {"fx1":{"effect": self.fx1.GetValue(),
                     "slot1": "",
                     "slot2": ""},
              "fx2":{"effect": self.fx2.GetValue(),
                     "slot1": "",
                     "slot2": ""}
              }
        self.model.changeEffects(fx)
        
    def update(self):
        self.updateCombo(self.btn1Sample)
        self.updateCombo(self.btn2Sample)
        self.updateCombo(self.btn3Sample)
        self.updateCombo(self.btn4Sample)
        self.updateCombo(self.btn5Sample)
        self.updateCombo(self.btn6Sample)
        self.updateCombo(self.btn7Sample)
        self.updateCombo(self.btn8Sample)
        self.updateCombo(self.btn9Sample)
        self.updateCombo(self.btn10Sample)
        self.updateCombo(self.btn11Sample)
        self.updateCombo(self.btn12Sample)
        self.updateCombo(self.btn13Sample)
        self.updateCombo(self.btn14Sample)
        self.updateCombo(self.btn15Sample)
        self.updateCombo(self.btn16Sample)

